module.exports = function ($scope, $resource, $modalInstance, item, toaster) {
    
    $scope.policyRuleInfo = {};
    var url = '/api/as/atc/policyrule/addPolicyRule';
    if(item){
        $scope.policyRuleInfo.title = item.title;
        $scope.policyRuleInfo.context = item.context;
        $scope.policyRuleInfo.code = item.code;
        url = '/api/as/atc/policyrule/updatePolicyRule';
    } else {
        $scope.policyRuleInfo.code = 'R' + new Date().getTime();
    }

    
    
    //确认保存 
    $scope.ok = function() {

        $resource(url, {}, {}).save($scope.policyRuleInfo, function(res){
            if (res.errcode === 0) {
                toaster.success({title: '', body: '保存成功'});
                $modalInstance.close($scope.policyRuleInfo);
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
    
    //关闭
    $scope.close = function () {
        $modalInstance.dismiss('cancel');
    }

};